package com.cbn.ibcp.jishiting.gs.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.gs.cms.domain.Node;
import com.cbn.ibcp.jishiting.gs.cms.domain.Org;
import com.cbn.ibcp.jishiting.gs.cms.mapper.NodeMapper;
import com.cbn.ibcp.jishiting.gs.cms.service.INodeService;
import com.cbn.ibcp.jishiting.gs.cms.service.IOrgService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class NodeServiceImpl implements INodeService {

    private final NodeMapper nodeMapper;

    private final IOrgService orgService;

    @DataSource(DataSourceType.gs_cms)
    @Override
    public Node selectById(Long id) {
        if (Objects.isNull(id)) {
            return null;
        }
        return nodeMapper.selectById(id);
    }

    @DataSource(DataSourceType.gs_cms)
    public Node selectByOrgId(Long orgId) {
        LambdaQueryWrapper<Node> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Node::getOrgIdx, orgId);
        return nodeMapper.selectOne(lambdaQueryWrapper);
    }

    @DataSource(DataSourceType.gs_cms)
    @Override
    public List<Node> selectList() {
        LambdaQueryWrapper<Node> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Node::getIsEnable, 1);
        queryWrapper.eq(Node::getType, 1);
        return nodeMapper.selectList(queryWrapper);
    }
}
